/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.boot.web.controller;

import com.iwindplus.boot.domain.context.HeaderContextHolder;
import com.iwindplus.boot.domain.context.UserContextHolder;
import com.iwindplus.boot.web.manager.context.ContextTransManager;
import com.iwindplus.boot.domain.vo.TraceInfoVO;
import com.iwindplus.boot.domain.vo.UserBaseVO;
import com.iwindplus.boot.util.HttpsUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.Map;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 基础控制层类.
 *
 * @author zengdegui
 * @since 2018/9/1
 */
@Slf4j
@Getter
public class BaseController {

    @Resource
    private HttpServletRequest request;

    @Resource
    private HttpServletResponse response;

    @Resource
    private ContextTransManager contextTransManager;

    /**
     * 获取request请求参数.
     *
     * @return Map<String, String>
     */
    public Map<String, String> getParameterMap() {
        return HttpsUtil.getParams(this.request);
    }

    /**
     * 获取登录用户信息.
     *
     * @return UserBaseVO
     */
    protected UserBaseVO getUserInfo() {
        return UserContextHolder.getContext();
    }

    /**
     * 获取跟踪信息.
     *
     * @return TraceInfoVO
     */
    protected TraceInfoVO getTraceInfo() {
        return this.contextTransManager.getTraceInfo();
    }

    /**
     * 获取请求头信息.
     *
     * @return Map<String, String>
     */
    protected Map<String, String> getHeaderMap() {
        return HeaderContextHolder.getContext();
    }
}
